package com.cssw.fyzb.web.controller;

import com.cssw.fyzb.base.web.context.UserContext;
import com.cssw.fyzb.base.web.domain.AjaxData;
import com.cssw.fyzb.base.web.domain.AjaxPage;
import com.cssw.fyzb.web.dto.AcctOperationGDto;
import com.cssw.fyzb.web.dto.FeedbackDto;
import com.cssw.fyzb.web.service.AcctService;
import com.cssw.fyzb.web.vo.AcctVo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@ApiModel("账户余额管理")
@RestController
@RequestMapping("/acct")
public class AcctController {
    @Autowired
    AcctService acctService;

    @ApiOperation(value = "果子列表", response = AjaxPage.class)
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public AjaxPage<AcctVo> list(int page, int limit, String search,String supUserId) {
        Map param = new HashMap();
        param.put("keyword",search);
        param.put("supUserId",supUserId);
        return acctService.list(page, limit, param);
    }

    @ApiOperation(value = "果子调账", response = AjaxData.class)
    @PostMapping(value = "/operation")
    public AjaxData operation(@RequestBody AcctOperationGDto dto) {
        boolean result = acctService.update(dto.getUserId(),"G", dto.getType(),
                dto.getNum(),UserContext.getUserId(),dto.getRemark());
        if (result) return AjaxData.success();
        else return AjaxData.failure();
    }

}
